package org.nowcoder.huawei.c200;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 44：Family Day
 */

public class HC044 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n, m;
        String[] s = br.readLine().split(" ");
        n = Integer.parseInt(s[0]);
        m = Integer.parseInt(s[1]);

        int[][] grid = new int[n][m];
        for (int i = 0; i < n; i++) {
            String[] s1 = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                grid[i][j] = Integer.parseInt(s1[j]);
            }
        }
        familyDay(grid, n, m);
    }

    public static void familyDay(int[][] grid, int n, int m) {
        //(0,0) -> (i,j) 的路径数
        int[][] dp = new int[n][m];

        //初始化
        for (int i = 0; i < m; i++) {
            if (grid[0][i] == 0) {
                dp[0][i] = 1;
            } else {
                break;
            }
        }
        for (int i = 0; i < n; i++) {
            if (grid[i][0] == 0) {
                dp[i][0] = 1;
            } else {
                break;
            }
        }
        //状态转移方程
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < m; j++) {
                if (grid[i][j] == 0) {
                    if (grid[i][j - 1] == 0) {
                        dp[i][j] += dp[i][j - 1];
                    }
                    if (grid[i - 1][j] == 0) {
                        dp[i][j] += dp[i - 1][j];
                    }
                } else {
                    dp[i][j] = 0;
                }
            }
        }
        System.out.println(dp[n - 1][m - 1]);
    }
}
